from pages.base_page import BasePage


class RecommendPage(BasePage):
    activity = '.activity.index.HomeIndexActivity'
    add_button_xpath = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_topic_detail_publish_iv"]'
    add_trade_button = '//*[@resource-id="cool.dingstock.mobile:id/transaction_title_tv"]'
    trend_input_box_xpath = '//*[@resource-id="cool.dingstock.mobile:id/circle_activity_dynamic_edit_edit"]'
    first_topic_xpath = '//*[@text="长津湖"]'
    trend_add_image_xpath = '//*[@resource-id="cool.dingstock.mobile:id/layout_dynamic_image"]'
    first_image_xpath = '//*[@resource-id="cool.dingstock.mobile:id/mCheckBoxPanel"]/android.widget.CheckBox[1]'
    next_step_xpath = '//*[@resource-id="cool.dingstock.mobile:id/tv_rightBtn"]'
    publish_xpath = '//*[@resource-id="cool.dingstock.mobile:id/tv_publish"]'
    newest_route_xpath = '//*[@text="最新"]'
    follow_route_xpath = '//*[@text="关注"]'
    trade_route_xpath = '//*[@text="交易"]'
    near_route_xpath = '//*[@text="附近"]'
    topic_route_xpath = '//*[@text="话题"]'
    recommend_route_xpath = '//*[@text="推荐"]'
    search_button = '//*[@resource-id="cool.dingstock.mobile:id/search_iv"]'
    home_route_xpath = '//*[@resource-id="cool.dingstock.mobile:id/home_activity_bottom_tab_view"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]'
    select_trade_xpath = '//*[@resource-id="cool.dingstock.mobile:id/transaction_title_tv"]'
    trade_input_xpath = '//*[@resource-id="cool.dingstock.mobile:id/goods_content_et"]'
    trade_image_xpath = '//*[@resource-id="cool.dingstock.mobile:id/picture_rv"]/android.widget.FrameLayout[1]'
    trade_select_goods_xpath = '//*[@resource-id="cool.dingstock.mobile:id/select_goods_tv"]'
    first_good_xpath = '//*[@resource-id="cool.dingstock.mobile:id/goods_rv"]/android.view.ViewGroup[1]'
    first_size_xpath = '//*[@resource-id="cool.dingstock.mobile:id/sku_size_rv"]/android.view.ViewGroup[1]'
    trade_price_expand = '//*[@resource-id="cool.dingstock.mobile:id/sku_price_tv"]'
    trade_price_input = '//*[@resource-id="cool.dingstock.mobile:id/price_et"]'
    mine_center = '//*[@resource-id="cool.dingstock.mobile:id/home_activity_bottom_tab_view"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[4]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]'
    choosed_trade_goods_name = '//*[@resource-id="cool.dingstock.mobile:id/goods_title_tv"]'
    all_album = '//*[@resource-id="cool.dingstock.mobile:id/tv_title"]'
    second_album = '//*[@resource-id="cool.dingstock.mobile:id/mSetRecyclerView"]/android.widget.FrameLayout[2]/android.widget.LinearLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]'
    flash_sale = '//*[@resource-id="cool.dingstock.mobile:id/item_title_1"]'
    focus_area = '//*[@resource-id="cool.dingstock.mobile:id/item_title_2"]'
    top_lottery = '//*[@resource-id="cool.dingstock.mobile:id/item_title_3"]'
    back_button = '//*[@resource-id="cool.dingstock.mobile:id/common_titlebar_left_icon"]'
    message = '//*[@resource-id="cool.dingstock.mobile:id/home_top_bar"]/android.widget.FrameLayout[2]'
    release_button = '//*[@resource-id="cool.dingstock.mobile:id/home_activity_bottom_tab_view"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]'
    monitor_button = '//*[@resource-id="cool.dingstock.mobile:id/home_activity_bottom_tab_view"]/android.widget.LinearLayout[1]/android.widget.LinearLayout[3]/android.view.ViewGroup[1]/android.widget.FrameLayout[1]'
    search_history = '//*[@resource-id="cool.dingstock.mobile:id/history_title_tv"]'

    def switch_home(self):
        """切换到主页"""
        self.click_xpath(self.home_route_xpath)

    def switch_follow(self):
        """切换到关注tab"""
        self.click_xpath(self.follow_route_xpath)

    def switch_newest(self):
        """切换到最新tab"""
        self.click_xpath(self.newest_route_xpath)

    def switch_trade(self):
        """切换到交易tab"""
        self.click_xpath(self.trade_route_xpath)

    def switch_nearest(self):
        """切换到附近tab"""
        self.click_xpath(self.near_route_xpath)

    def switch_recommend(self):
        """切换到推荐tab"""
        self.click_xpath(self.recommend_route_xpath)

    def switch_topic(self):
        """切换到话题tab"""
        self.click_xpath(self.topic_route_xpath)

    def click_add_button(self):
        """点击页面新建按钮"""
        self.click_xpath(self.add_button_xpath)

    def trend_input_text(self, text):
        """新建动态文本框输入内容text"""
        self.set_xpath_text(self.trend_input_box_xpath, text)

    def choose_topic(self):
        """选择动态话题：长津湖"""
        self.click_xpath(self.first_topic_xpath)

    def choose_image(self):
        """动态插入图片，选择相册第一张，点击下一步"""
        self.click_xpath(self.trend_add_image_xpath)
        self.click_xpath(self.all_album)
        self.click_xpath(self.second_album)
        self.click_xpath(self.first_image_xpath)
        self.click_xpath(self.next_step_xpath)

    def click_publish(self):
        """点击发布按钮"""
        self.click_xpath(self.publish_xpath)

    def choose_add_trade(self):
        """选择发布交易"""
        self.click_xpath(self.select_trade_xpath)

    def trade_input_content(self, text):
        """输入发布交易的文本内容"""
        self.set_xpath_text(self.trade_input_xpath, text)

    def click_select_goods(self):
        """点击选择商品"""
        self.click_xpath(self.select_trade_xpath)

    def switch_mine(self):
        """切换到用户中心"""
        self.click_xpath(self.mine_center)

    def choose_create_trade(self):
        """选择新建交易"""
        self.click_xpath(self.add_trade_button)

    def input_trade_text(self, text):
        """输入交易文本"""
        self.set_xpath_text(self.trade_input_xpath,text)

    def choose_trade_image(self):
        """选择相册第一张图片为交易图片"""
        self.click_xpath(self.trade_image_xpath)
        self.click_xpath(self.all_album)
        self.click_xpath(self.second_album)
        self.click_xpath(self.first_image_xpath)
        self.click_xpath(self.next_step_xpath)

    def choose_trade_goods(self,price):
        """选择交易商品：adidas yeezy，尺码选择第一个，输入价格"""
        self.click_xpath(self.trade_select_goods_xpath)
        self.click_xpath(self.first_good_xpath)
        self.click_xpath(self.first_size_xpath)
        self.click_xpath(self.trade_price_expand)
        self.set_xpath_text(self.trade_price_input,price)
        return self

    def get_trade_goods_name(self):
        """获取发布交易的商品名称"""
        return self.get_xpath_text(self.choosed_trade_goods_name)

    def into_flash_sale(self):
        """进入秒杀神器"""
        self.click_xpath(self.flash_sale)
        
    def into_focus_area(self):
        """进入关注地区"""
        self.click_xpath(self.focus_area)
        
    def into_top_lottery(self):
        """进入尖货抽签"""
        self.click_xpath(self.top_lottery)

    def go_back(self):
        """返回上一级"""
        self.click_xpath(self.back_button)
        
    def switch_message(self):
        """进入私信和通知页面"""
        self.click_xpath(self.message)

    def switch_release(self):
        """切换到发售"""
        self.click_xpath(self.release_button)
        
    def switch_monitor(self):
        """切换到监控"""
        self.click_xpath(self.monitor_button)
        
    def click_search(self):
        """点击搜索"""
        self.click_xpath(self.search_button)
        return self.get_xpath_text(self.search_history)